<template>
  <div>
    <el-menu
        mode="horizontal"
        background-color="#545c64"
        text-color="#fff">
      <el-menu-item @click="gouser()">返回 </el-menu-item>
      <el-menu-item @click="unlogin()"style="position: fixed;right: 19px;top: 8px">注销</el-menu-item>
    </el-menu>
    <div style="width: 280px;margin: 0 auto;position: relative; top: 60px">

      <h2 style="width: 145px;margin: 0 auto">注册</h2>
      <br/>
      用户名：<el-input v-model="logindata.username" placeholder="请输入用户名" style="width: 200px"></el-input>
      <br/><br/>
      密码：<el-input v-model="logindata.password" placeholder="请输入密码" style="width: 200px; position: relative; right: -16px" show-password></el-input>
      <br/><br/>
      姓名：<el-input v-model="logindata.nickname" placeholder="请输入姓名" style="width: 200px; position: relative; right: -16px"></el-input>
      <br/><br/>
      年龄：<el-input v-model="logindata.age" placeholder="请输入年龄" style="width: 200px; position: relative; right: -16px"></el-input>
      <br/><br/>
      性别：<el-input v-model="logindata.sex" placeholder="请输入性别" style="width: 200px; position: relative; right: -16px"></el-input>
      <br/><br/>
      地址：<el-input v-model="logindata.address" placeholder="请输入地址" style="width: 200px; position: relative; right: -16px"></el-input>
      <br/><br/>
      身份：<el-input v-model="logindata.identity" placeholder="请输入身份" style="width: 200px; position: relative; right: -16px"></el-input>
      <br/><br/>

      <br/>
      <div style="width:60px;margin: 0 auto;">
        <el-button @click="register">注册</el-button>
      </div>
    </div>
  </div>

</template>

<script>
export default {
  created() {
  },
  data(){
    return{
      logindata: {
        username: '',
        password: '',
        nickname:'',
        age:'',
        sex:'',
        address:'',
        identity:'',
      }
    }

  },
  methods:{
    register(){
      // axios.post('/user/register/'+this.logindata.username+'/'+this.logindata.password+'/'+this.logindata.nickname+'/'+this.logindata.age+'/'+this.logindata.sex+'/'+this.logindata.address+'/'+this.logindata.identity).then(res=> {
      //   if(res.data.code===10000){
      //     this.$message.success(res.data.msg);
      //     this.$router.push('/user')
      //   }else{
      //     this.$message.error(res.data.msg);
      //     console.log('no');
      //     this.logindata='';
      //   }
      // }),
      axios.post('/user/register',this.logindata).then(res=> {
        if(res.data.code===10000){
          this.$message.success(res.data.msg);
          this.$router.push('/user')
        }else{
          this.$message.error(res.data.msg);
          console.log('no');
          this.logindata='';
        }
      })
    },
    gouser() {
      this.$router.push('/user/studentsearch');
    },
    unlogin(){
      axios.post('/user/logout').then(res=> {
        if(res.data.code===10000){
          this.$message.success(res.data.msg);
          this.$router.push('/login');
        }else{
          this.$message.error(res.data.msg);
        }
      })
    },
  }
}
</script>

<style scoped>

</style>